{extend name="../public/header" /}
{block name="body"}
<body>
{include file="../public/top" uname="$roleInfo.uname" lv="$roleInfo.ulv" ls="$roleInfo.uyxb" jp="$roleInfo.uczb" /}
<div class="subject main">
    <div class="layui-row">
        <div class="content">
            <div class="current">
                <span class="position">{$roleInfo.map.mname}</span>
                <span class="state">{if $roleInfo.map.ispvp==0}[安全区]{else/}[PVP]{/if}</span>
                <span class="info ajax-goto" data-url="{:url('home/index')}">返回</span>
            </div>
            <div class="npc">
                <div class="layui-panel">
                    <div style="padding:10px;">
                        <span class="layui-breadcrumb" lay-separator="|">
                            <a class="ajax-goto" data-url="{:url('package/myEquip')}">装备</a>
                            <a class="ajax-goto" data-url="{:url('package/myProp')}">道具</a>
                            <a class="ajax-goto" data-url="{:url('package/myDrug')}">丹药</a>
                            <a class="ajax-goto" data-url="{:url('package/myTask')}">任务</a>
                        </span>
                        <div class="layui-row layui-col-space10 shop" style="border: #D5CBCB 1px solid;">
                            {volist name="list" id="vo"}
                            <div class="layui-col-xs4">
                                <div class="grid-demo">
                                    <div class="shop-title">{$vo.djname} x{$vo.djsum}</div>
                                    <div class="shop-des">{$vo.djinfo}</div>
                                    <div class="shop-lable">
                                        <a class="layui-btn layui-btn-xs layui-btn-primary layui-border-blue ajax-sell" data-act="sell" data-id="{$vo.id}">售</a>
                                        <a class="layui-btn layui-btn-xs layui-btn-primary layui-border-blue ajax-act" data-act="lose" data-id="{$vo.id}">丢</a>
                                    </div>
                                </div>
                            </div>
                            {/volist}
                            {for start="1" end="$surplusLattice"}
                            <div class="layui-col-xs4">
                                <div class="grid-demo" style="height:90px;line-height:90px;background-color: #EFEFEF;">空</div>
                            </div>
                            {/for}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
{/block}
{block name="script"}
<script>
    layui.use(['jquery', 'form', 'layajax', 'upload', 'flow', 'element'], function () {
        var $ = layui.jquery
            , layajax = layui.layajax
            , upload = layui.upload
            , element = layui.element
            , flow = layui.flow
            , form = layui.form;

        $('.ajax-act').on('click', function () {
            var act = $(this).data('act');
            var id = $(this).data('id');

            console.log('act', act, 'id', id);

            var map = {};
            map['act'] = act;
            map['id'] = id;

            $.post("{:url('propAct')}", map, function (res) {
                if (res.code == undefined) {
                    console.log('res为json字符串', res);
                    res = JSON.parse(res);
                } else {
                    console.log('res为json对象', res);
                }
                if (res.code == 1) {
                    layer.msg(res.msg, {icon: 1, time: 1000}, function (index) {
                        if (res.data.url != '' && res.data.url != undefined) {
                            window.location.href = res.data.url;
                        } else {
                            location.reload();
                        }
                    });
                } else {
                    layer.msg(res.msg);
                }
            });

        });

        $('.ajax-sell').on('click', function () {
            var act = $(this).data('act');
            var id = $(this).data('id');

            console.log('act', act, 'id', id);

            layer.open({
                title: '输入数量和价格',
                type: 1,
                content: '<div id="sellProp" style="width:100%;padding: 10px;box-sizing: border-box;">' +
                    '<input class="layui-input" name="num" placeholder="数量"><br>' +
                    '<input class="layui-input" name="price" placeholder="价格"><br>' +
                    '</div>',
                btn: ['确定', '取消'],
                yes: function (index, layero) {
                    var n = $(layero)[0];
                    var obja = $(n).contents().find("input[name='num']");
                    var objb = $(n).contents().find("input[name='price']");
                    var num = $(obja).val();
                    var price = $(objb).val();

                    if(num==0 || num=='' || num<0){
                        layer.msg('请输入数量');
                        return false;
                    }
                    if(price==0 || price=='' || price<0){
                        layer.msg('请输入价格');
                        return false;
                    }

                    console.log(act,id,num,price);
                    layer.close(index);

                    var map = {};
                    map['act'] = act;
                    map['id'] = id;
                    map['num'] = num;
                    map['pay'] = price;
                    $.post("{:url('propAct')}", map, function (res) {
                        if (res.code == undefined) {
                            console.log('res为json字符串', res);
                            res = JSON.parse(res);
                        } else {
                            console.log('res为json对象', res);
                        }
                        if (res.code == 1) {
                            layer.msg(res.msg, {icon: 1, time: 1000}, function (index) {
                                if (res.data.url != '' && res.data.url != undefined) {
                                    window.location.href = res.data.url;
                                } else {
                                    location.reload();
                                }
                            });
                        } else {
                            layer.msg(res.msg);
                        }
                    });
                },
                btn2: function (index) {
                    layer.close(index);
                }
            });

            /*
            layer.prompt({title: '输入价格，并确认', formType: 0}, function (price, index) {
                layer.close(index);
                console.log('price', price);

                var map = {};
                map['act'] = act;
                map['id'] = id;
                map['pay'] = price;

                $.post("{:url('equipAct')}", map, function (res) {
                    if (res.code == undefined) {
                        console.log('res为json字符串', res);
                        res = JSON.parse(res);
                    } else {
                        console.log('res为json对象', res);
                    }
                    if (res.code == 1) {
                        layer.msg(res.msg, {icon: 1, time: 1000}, function (index) {
                            if (res.data.url != '' && res.data.url != undefined) {
                                window.location.href = res.data.url;
                            } else {
                                location.reload();
                            }
                        });
                    } else {
                        layer.msg(res.msg);
                    }
                });
            });
            */

        });

        $('.ajax-sellProp').live('click', function (){
            console.log('111111');
            var act = $(this).data('act');
            var id = $(this).data('id');
        });

        form.render();
    });
</script>
{/block}